package cn.bqjr.eily.web.utils;

import cn.bqjr.eily.utils.I18nUtils;
import cn.bqjr.eily.web.exception.exclass.RequestException;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.util.Collection;

public class AssertUtils extends Assert {
    public static void equals(Serializable val1, Serializable val2) {
        equals(val1, val2, I18nUtils.getMsg("error.request.illegalArgument"));
    }

    public static void equals(Serializable val1, Serializable val2, String msg) {
        if (null == val1 || null == val2 || !val1.equals(val2)) {
            throw new RequestException(msg);
        }
    }

    public static void notEquals(Serializable val1, Serializable val2) {
        notEquals(val1, val2, I18nUtils.getMsg("error.request.illegalArgument"));
    }

    public static void notEquals(Serializable val1, Serializable val2, String msg) {
        if (null == val1 || val1.equals(val2)) {
            throw new RequestException(msg);
        }
    }

    public static void hasElements(Collection<?> collection, String msg) {
        if (null == collection || collection.isEmpty()) {
            throw new RequestException(msg);
        }
    }

    public static void hasNoElements(Collection<?> collection, String msg) {
        if (null != collection && !collection.isEmpty()) {
            throw new RequestException(msg);
        }
    }

    public static void greaterThan(int var1, int target, String msg) {
        if (var1 < target) {
            throw new RequestException(msg);
        }
    }

    public static void lessThan(int var1, int target, String msg) {
        if (var1 > target) {
            throw new RequestException(msg);
        }
    }
}
